define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	
	$scope.form.father_id=params.father_id;
	//查询所有单位
	httpService.post(app.urls.unit_selectUnit,{},function(data){
		if("0000" === data.code){
			$scope.units = data.data;
		}else{
			alert(data.msg);
		}
	});
	
	function confirmEnding(str, target) {
		  var start = str.length-target.length;
		  var arr = str.substr(start,target.length);
		  if(arr == target){
		    return true;
		  }
		 return false;
	}
	
	function confirmEnding(str, target) {
		  var start = str.length-target.length;
		  var arr = str.substr(start,target.length);
		  if(arr == target){
		    return true;
		  }
		 return false;
	}
	
	$scope.saveForm = function(){
 		if($scope.formCheck()) {
 			if($scope.form.sfzjh=="" || $scope.form.sfzjh==null){
 				$scope.form.sfzjh='9999999'+$scope.form.phone
 			}else{
 				if(confirmEnding($scope.form.sfzjh,$scope.form.phone)){
 					
 				}else{
 					console.info("进入");
	 				var idcard = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
	 				if (idcard.test($scope.form.sfzjh)) {
	 				} else {
	 					eventBusService.publish('modal.alert', {"title":"操作提示","content":"请输入正确身份证件号或填写以手机号结尾的18位数字"});
	 					return;
	 				}
 				}
 			}
			$scope.form.type = '6';
			httpService.post(app.urls.guest_selectRepeat,$scope.form,function(data) {
				if ("0000" === data.code) {
					// httpService.post(app.urls.user_insert,$scope.form,function(data) {
					// 	if ("0000" === data.code) {
					// 		$scope.form.id=$scope.form.fk_user = data.data;
							httpService.post(app.urls.guest_insert, $scope.form, function (data) {
								if ("0000" === data.code) {
									httpService.post(app.urls.user_resetPwd,{"ids":data.data,"type":'6'}, function(data) {
										if ("0000" === data.code) {
											var menu = {"url":"modules/content/usermanagement/guestCenter/list?father_id="+params.father_id+"&gzdwpk="+$scope.form.gzdwpk+"&rsdwpk="+$scope.form.rsdwpk};
											eventBusService.publish("modules.content.load",menu);
										} else {
											alert(data.msg);
										}
									});	
								} else {
									alert(data.msg);
								}
							});
					// 	} else {
					// 		alert(data.msg);
					// 	}
					// });
				}else {
					alert(data.msg);
				}
			});	
 		}
	 }
	//返回
	$scope.goback = function(){
		var menu = {"url":"modules/content/usermanagement/guestCenter/list?father_id="+params.father_id};
		eventBusService.publish("modules.content.load",menu);
	}
}}});